/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: Dec 31, 2009
 * Time: 10:59:31 AM
 * To change this template use File | Settings | File Templates.
 */
import dk.brics.automaton.Automaton;
import java.util.*;

public class StringEdge
{

    private StringEdge()
    {
    }

    public StringEdge(String s, Object obj)
    {
        gap = s;
        labels = Automaton.makeEmpty();
        origins = new HashSet();
        origins.add(obj);
    }

    public StringEdge(String s, Collection collection)
    {
        gap = s;
        labels = Automaton.makeEmpty();
        origins = new HashSet(collection);
    }

    public boolean addLabels(Automaton automaton)
    {
        boolean flag = !automaton.subsetOf(labels);
        if(automaton.isEmpty())
            labels = automaton;
        else
        if(flag)
        {
            labels = labels.union(automaton);
            labels.minimize();
        }
        return flag;
    }

    public boolean addLabel(String s)
    {
        return addLabels(Automaton.makeString(s));
    }

    public boolean addAnyString()
    {
        return addLabels(Automaton.makeAnyString());
    }

    public Automaton getLabels()
    {
        return labels;
    }

    public String getGap()
    {
        return gap;
    }

    public Collection getOrigins()
    {
        return origins;
    }

    public Object clone()
    {
        StringEdge stringedge = new StringEdge();
        stringedge.gap = gap;
        stringedge.labels = labels;
        stringedge.origins = new HashSet(origins);
        return stringedge;
    }

    String gap;
    Automaton labels;
    Set origins;
}
